Skip to content

editoast: fix a couple issues in new authentication middlewares#16980

Draft
leovalais wants to merge 2 commits into
devfrom
lva/rqrpxvntuzum
Draft

editoast: fix a couple issues in new authentication middlewares#16980
leovalais wants to merge 2 commits into
devfrom
lva/rqrpxvntuzum

Conversation

@leovalais
Copy link
Copy Markdown
Contributor

leovalais added 2 commits May 29, 2026 15:48
The middleware pushed in request extensions the user and the roles
of the impersonator instead of the impersonated user.

- Reworks and simplifies the flow of the middleware.
- Fixes impersonation processing.
- Adds a test for `/authz/me` to have a bit of impersonation coverage.
- Adds a request extension `.impersonate`.
- Removes useless referencing of `impl AsRef`.

Signed-off-by: Léo VALAIS <leovalais+git@proton.me>
- Makes sure the user is created if it doesn't exist.
- More consistent behavior when compared to other authentication modes.
- Adds a test for `/authz/me` to inspect the behavior.

Signed-off-by: Léo VALAIS <leovalais+git@proton.me>
@github-actions github-actions Bot added the area:editoast Work on Editoast Service label May 29, 2026
@leovalais leovalais self-assigned this May 29, 2026
@leovalais leovalais added the kind:bug Something isn't working label May 29, 2026
@leovalais leovalais moved this to Awaiting merge in Board PI 20 May 29, 2026
Copy link
Copy Markdown
Contributor

@Sh099078 Sh099078 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR

}

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn whoami_impersonation() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe also test that non-admin users cannot impersonate

conn.transaction(async |conn| {
let user =
editoast_models::User::retrieve_by_identity(identity, conn.clone()).await?;
warn_mismatched_name(&user, identity, name);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the warn_mismatched_name might be a bit confusing here. I would interpret it as "always send a warning about the user name at this point of execution" when it actually checks whether there is a name mismatch and only logs a warning if there is one.

Maybe rename it to check_name_mismatch, warn_on_name_mismatch or something alike ?

Comment on lines +207 to 212
if let Some(impersonator) = impersonator {
check_impersonation_privilege(regulator.openfga(), &impersonator).await?;
} else {
register_origin_user(conn.clone(), (impersonator_identity, impersonator_name))
.await?;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the impersonator does not exist yet we skip the impersonation check and create the impersonator instead ? That feels wrong

If I'm not mistaken it means that trying to impersonate with a user which does not exist always succeeds even though it is supposed to be reserved to admins

@@ -149,54 +150,83 @@ pub(in crate::views) async fn authentication_validation_middleware(
Ok((Some(user), ::authz::v2::subject_roles(authz_user)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we only call that method on nonexistent user they should not have roles yet aswell ? Maybe we can either directly return an empty roles list keep retrieving the roles but in order to check that the retrieved roles list is indeed empty and panic if it is not ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:editoast Work on Editoast Service kind:bug Something isn't working

Projects

Status: Awaiting merge

Development

Successfully merging this pull request may close these issues.

2 participants